package org.helsoft.mojo;

import java.io.File;
import java.io.IOException;

import org.apache.maven.plugin.MojoExecutionException;
import org.apache.maven.plugin.MojoFailureException;
import org.codehaus.plexus.util.FileUtils;
import org.helsoft.mojo.api.AbstractPDEMojo;

/**
 * 
 * @author hesteguet
 * @goal clean
 * 
 * @phase clean
 */
public class CleanMojo extends AbstractPDEMojo {

	@Override
	public void execute() throws MojoExecutionException, MojoFailureException {
		File dir = getLibrairiesLocation();
		if (dir != null) {
			try {
				FileUtils.deleteDirectory(dir);
			} catch (IOException e) {
				fail(e);
			}
		}
		
		if (!mustPreservePDEPom()) {
			File pom = getPDEPom();
			if (pom != null && pom.isFile()) {
				pom.delete();
			}
		}
	}
	
}
